package com.lianheng.cms.common.gen;

import com.jfinal.kit.PathKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.druid.DruidPlugin;

import javax.sql.DataSource;

/**
 * 生成jfinalModel模板
 **/
public class JFinalConfig {

    protected static String url = "jdbc:mysql://localhost:3306/website";
    protected static String name = "root";
    protected static String pwd = "root";
    /**
     * 基本包名字
     **/
    protected static String packageBase = "com.lianheng.cms.other";
    /**
     * maven工程结构
     **/
    protected static String projectType = "/src/main/java/";
    /**
     * 基本写出文件路径
     **/
    protected String baseModelOutputDir = PathKit.getWebRootPath() + projectType;
    /**
     * model包
     **/
    protected String modelPackageName = packageBase + ".model";
    /**
     * dto
     **/
    protected String dtoPackageName = packageBase + ".dto";
    /**
     * model包下base包
     **/
    protected String baseModelPackageName = modelPackageName + ".base";
    /**
     * model包下mapping包
     **/
    protected String mappingKitPackageName = modelPackageName + ".mapping";
    /**
     * 自定义MappingKit类名
     **/
    protected String mappingKitClassName = "MappingKit";
    /**
     * 数据库表前缀
     **/
    protected String tablePrefix = "t_";
    protected String swaggerTemplate = "tpl/swagger_template.jf";
    protected String baseModelTemplate = "tpl/base_model_template.jf";
    protected String srcFolder = "src";
    protected String tpl = "/tpl";
    //  protected String tpl = "/mybatistpl";
    protected String basePath = "";
    protected static DataSource dataSource = null;
    protected static ActiveRecordPlugin arp = null;

    public JFinalConfig() {

    }

    protected static DruidPlugin dp = new DruidPlugin(url, name, pwd);

    static {
        arp = new ActiveRecordPlugin(dp);
        dp.start();
        arp.start();
        arp.setShowSql(true);
        dataSource = dp.getDataSource();
    }

    public static void setName(String name) {
        JFinalConfig.name = name;
    }
}
